package com.serie402.web.jsf.mb;

import java.util.Calendar;
import java.util.List;

import org.apache.log4j.Logger;

import com.kiss.fw.jsf.mb.AbstractManagedBean;
import com.kiss.fw.utils.Util;
import com.serie402.common.utils.Constants;

public class GenericManagedBean extends AbstractManagedBean {
	private static Logger logger = Logger.getLogger(GenericManagedBean.class);
	private static Calendar DR_CALENDAR = Calendar.getInstance(Constants.Instances.DR_LOCALE);
	
	public String getGoogleAnalytics() {
		logger.debug("GenericManagedBean.getGoogleAnalytics()");
		// TODO: Update to use Constants Mapping
		return Util.getProperty("application.google.analytics");
	}
	
	public String getCurrentDate() {
		logger.debug("GenericManagedBean.getCurrentDate()");
		return Util.getDisplayDate(DR_CALENDAR, Constants.Instances.DR_LOCALE);
	}
	
	@SuppressWarnings("unchecked")
	public String getPageMessages() {
		List<String> pageMessages = (List<String>)getRequestScope().get(Constants.Mappings.PAGE_MESSAGES_LIST);
		String returnVal = "";
		
		if(pageMessages != null) {
			StringBuffer sb = new StringBuffer();
			
			for(int i=0; i < pageMessages.size(); i++) {
				sb.append(pageMessages.get(i));
			}
			
			returnVal = sb.toString();
		}
		
		return returnVal;
	}
}